package net.suncaper.demo.controller;

import net.suncaper.demo.service.HotelManageService;
import net.suncaper.demo.domain.hotel_information;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
@RequestMapping("/user")

public class HotelManageController {

    @Autowired
    private HotelManageService hotelManageService;

//    @Value("${upload.base-dir}")
//    private uploadBaseDir;
//
    @GetMapping("/add")
    public String addPage(Model model){
        model.addAttribute("user",new hotel_information());
        return "/pages/user/add-hotel";
    }


    @GetMapping("update")
    public String editPage(int hotel_id,Model model){
            model.addAttribute("user", hotelManageService.findUserById(hotel_id));
        return "/pages/user/add-hotel";
    }

    @PostMapping("/add")
    public  String saveUser(hotel_information hotel_information) {
            hotelManageService.savehotel_information(hotel_information);
            return "redirect:/user";
    }


    @GetMapping("/delete/{hotel_id}")
    public  String deleteUserById(@PathVariable("hotel_id") int hotel_id){
        hotelManageService.deletehotel_information(hotel_id);
        return "redirect:/user";
    }


    @RequestMapping
public  String Userpage(Model model,
                        @RequestParam(value="hotel_id",required = false) String hotel_id){
    List<hotel_information> users = hotelManageService.findUser(hotel_id);
        model.addAttribute("users",users) ;

    return "pages/user/list";
}
}
